package com.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.config.exception.GlobalExcetion;
import com.example.domain.BusFriendGroup;
import com.example.feign.NodeFeignService;
import com.example.feign.UserFeignService;
import com.example.service.BusFriendGroupService;
import com.example.mapper.BusFriendGroupMapper;
import com.example.system.domain.BusSystemTableUser;
import com.example.system.domain.PageData;
import com.example.system.service.BusSystemTableService;
import com.example.system.service.BusSystemTableUserService;
import com.example.util.sql.DBSql;
import com.example.util.sql.SqlGenerator;
import com.example.util.sql.SqlResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;
import java.util.Date;

/**
* @author CETC
* @description 针对表【bus_friend_group_1】的数据库操作Service实现
* @createDate 2025-11-05 09:04:57
*/
@Service
public class BusFriendGroupServiceImpl extends ServiceImpl<BusFriendGroupMapper, BusFriendGroup>
    implements BusFriendGroupService {

    @Autowired
    private BusSystemTableUserService busSystemTableUserService;

    @Autowired
    private BusSystemTableService busSystemTableService;

    @Override
    public boolean getBusFriendGroup(String userId, String friendUserId) throws GlobalExcetion {
        BusSystemTableUser tableUser = busSystemTableUserService.selectByUserId(userId,BusFriendGroup.class);
        String tableName=tableUser.generateUnionAllTableUserId();
        int count=this.baseMapper.getBusFriendGroupCount(tableName,userId,friendUserId);
        return count>0;
    }

    @Override
    public BusFriendGroup saveBusFriendGroup(BusFriendGroup busFriendGroup) throws GlobalExcetion {
        if(busFriendGroup.getFriendUid()==null){
            throw new GlobalExcetion(1,"用户id为空");
        }
        busSystemTableUserService.saveObjectData(busFriendGroup);
        return busFriendGroup;
    }

    @Override
    public BusFriendGroup getBusFriendGroupByUUID(String uuid) throws GlobalExcetion {
        BusFriendGroup busFriendGroup=busSystemTableUserService.getObjectDataByUUID(uuid,BusFriendGroup.class);
        return busFriendGroup;
    }

    @Override
    public PageData<BusFriendGroup> pageBusFriendGroup(Page<BusFriendGroup> page, String uid) throws GlobalExcetion {
        return busSystemTableUserService.getPage(page,uid,BusFriendGroup.class);
    }

    @Override
    public boolean deleteBusFriendGroup(String uuid) throws GlobalExcetion {
        return busSystemTableUserService.deleteDataByUUID(uuid);
    }

    @Override
    public BusFriendGroup updateBusFriendGroup(BusFriendGroup busFriendGroup) throws GlobalExcetion {
        busSystemTableUserService.updateObjectDataByUUID(busFriendGroup);
        return busFriendGroup;
    }


}




